home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 079c.dms / 079c.adf / extra_source.lha / OTHER_SOURCE / SPIN3D.Amos / SPIN3D.amosSourceCode
Encoding:
AMOS Source Code  |  1992-02-26  |  4.1 KB  |  145 lines

  1. '
  2. '                  3d Spinner - Maverick of Nina Software
  3. '
  4. '                                 v0.14
  5. '
  6. '                              4 - 10 - 93 
  7. '
  8. '   MODIFICATIONS: v0.14 - Includes distance compensation. 
  9. '
  10. '   NOTE:  The documentation has been provided for those who need to 
  11. '          learn from this program.  One interesting thing which can 
  12. '          be learnt is that comments take time when the program  is 
  13. '          run in the interpreter.  What this means is for the prog- 
  14. '          ram to be viewed at  its best remove the comments  before 
  15. '          running (OR compile it).
  16. '
  17. Set Buffer 20
  18. Degree 
  19. Screen Open 0,320,256,16,0
  20. Flash Off 
  21. Curs Off 
  22. Hide 
  23. Cls 0
  24. Double Buffer 
  25. Autoback 0
  26. '
  27. Close Editor 
  28. Close Workbench 
  29. '
  30. Dim PNTS(50,12),FACES(50,3),SYN(360),COZ(360),OBJ(5,2),EYE(3)
  31. Global PNTS(),SYN(),COZ(),S,FACES(),OBJ(),EYE()
  32. SETUP
  33. PITCH=0
  34. YAW=0
  35. DELTADEG=15
  36. '
  37. '   Main Loop
  38. '
  39. Repeat 
  40.    If Not Fire(1)
  41.       Add PITCH,DELTADEG*(Jup(1)-Jdown(1)),DELTADEG To 360
  42.       Add YAW,DELTADEG*(Jleft(1)-Jright(1)),DELTADEG To 360
  43.    Else 
  44.       Add EYE(2),DELTADEG*(Jup(1)-Jdown(1))
  45.       Add EYE(1),DELTADEG*(Jleft(1)-Jright(1))
  46.    End If 
  47.    ROTATE[YAW,PITCH]
  48.    Screen Swap 
  49.    Wait Vbl 
  50.    Cls 0
  51. Until Mouse Key<>0
  52. '
  53. '   End of program 
  54. '
  55. Procedure SETUP
  56.    '
  57.    '    This procedure is used to setup the arrays.  SYN contains the sine
  58.    '    values for deg=0 to 360.  COZ is the same for the cosine values.
  59.    '    PNTS contains the points for the PNTSect:-
  60.    '      PNTS(n,1) = x1   PNTS(n,2) = y1   PNTS(n,3) = z1 ...  
  61.    '      PNTS(n,9) = z3  
  62.    '
  63.    For COUNT=0 To 360
  64.       SYN(COUNT)=10000*Sin(COUNT)
  65.       COZ(COUNT)=10000*Cos(COUNT)
  66.    Next COUNT
  67.    Restore DATER
  68.    Repeat 
  69.       Inc PNTS(0,0)
  70.       For COUNT=1 To 3
  71.          Read PNTS(PNTS(0,0),COUNT)
  72.       Next COUNT
  73.       Read WORD$
  74.    Until WORD$="ENDPNTS"
  75.    Repeat 
  76.       Inc FACES(0,0)
  77.       For COUNT=0 To 3
  78.          Read FACES(FACES(0,0),COUNT)
  79.       Next COUNT
  80.       Read WORD$
  81.    Until WORD$="ENDDATA"
  82.    EYE(0)=0
  83.    EYE(1)=0
  84.    EYE(2)=0
  85.    EYE(3)=0
  86.    OBJ(1,0)=0
  87.    OBJ(1,1)=0
  88.    OBJ(1,2)=150
  89.    '
  90.    '   The following stores the number of faces in the PNTSect. 
  91.    '
  92.    '
  93.    '   The following contains the data for all the points in the PNTSect. 
  94.    '   Three points per polygon.  "CONT" is meaningless.  "ENDDATA" marks 
  95.    '   the end of the data for the PNTSect. 
  96.    '   The first field in the PNTSect is the colour of the polygon. 
  97.    '   For the hidden face calculations to be consistant the points MUST
  98.    '   be defined in an anticlockwise direction when looking at the face
  99.    '   "HEAD-ON" (ie. from out of the PNTSect in) 
  100.    '
  101.    DATER:
  102.    Data 0,-30,0,"GO"
  103.    Data 30,30,30,"GO"
  104.    Data -30,30,30,"GO"
  105.    Data 30,30,-30,"GO"
  106.    Data -30,30,-30,"ENDPNTS"
  107.    Data 8,1,3,2,"GO"
  108.    Data 4,1,2,4,"GO"
  109.    Data 6,1,4,5,"GO"
  110.    Data 4,1,5,3,"GO"
  111.    Data 15,2,5,4,"GO"
  112.    Data 14,2,3,5,"ENDDATA"
  113. End Proc
  114. Procedure ROTATE[YAW,PITCH]
  115.    For COUNT=1 To FACES(0,0)
  116.       PNTS(COUNT,4)=((PNTS(COUNT,3)*SYN(YAW))/10000)-((PNTS(COUNT,1)*COZ(YAW))/10000)
  117.       PNTS(COUNT,6)=((PNTS(COUNT,3)*COZ(YAW))/10000)+((PNTS(COUNT,1)*SYN(YAW))/10000)
  118.       PNTS(COUNT,5)=((PNTS(COUNT,2)*COZ(PITCH))/10000)-((PNTS(COUNT,6)*SYN(PITCH))/10000)
  119.       PNTS(COUNT,6)=((PNTS(COUNT,2)*SYN(PITCH))/10000)+((PNTS(COUNT,6)*COZ(PITCH))/10000)
  120.    Next COUNT
  121.    For COUNT=1 To FACES(0,0)
  122.       X1=PNTS(FACES(COUNT,1),4)
  123.       Y1=PNTS(FACES(COUNT,1),5)
  124.       Z1=PNTS(FACES(COUNT,1),6)
  125.       X2=PNTS(FACES(COUNT,2),4)
  126.       Y2=PNTS(FACES(COUNT,2),5)
  127.       Z2=PNTS(FACES(COUNT,2),6)
  128.       X3=PNTS(FACES(COUNT,3),4)
  129.       Y3=PNTS(FACES(COUNT,3),5)
  130.       Z3=PNTS(FACES(COUNT,3),6)
  131.       X1=(160*(EYE(1)+X1))/(OBJ(1,2)-Z1)
  132.       X2=(160*(EYE(1)+X2))/(OBJ(1,2)-Z2)
  133.       X3=(160*(EYE(1)+X3))/(OBJ(1,2)-Z3)
  134.       Y1=(128*(EYE(2)+Y1))/(OBJ(1,2)-Z1)
  135.       Y2=(128*(EYE(2)+Y2))/(OBJ(1,2)-Z2)
  136.       Y3=(128*(EYE(2)+Y3))/(OBJ(1,2)-Z3)
  137.       A=(Y1*(Z2-Z3))+(Y2*(Z3-Z1))+(Y3*(Z1-Z2))
  138.       B=(X1*(Z3-Z2))+(X2*(Z1-Z3))+(X3*(Z2-Z1))
  139.       C=(X1*(Y2-Y3))+(X2*(Y3-Y1))+(X3*(Y1-Y2))
  140.       Ink FACES(COUNT,0)
  141.       If C>0
  142.          Polygon X1+160,Y1+128 To X2+160,Y2+128 To X3+160,Y3+128
  143.       End If 
  144.    Next COUNT
  145. End Proc